﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonaLibrary.Commands.EditCommands
{
    public class DeleteEmployee : CommandBase
    {
        public override bool CanExecute(object parameter)
        {
            return parameter is int;
        }

        public override void Execute(object parameter)
        {
            DataModel.EmployeeRepository empRep = (DataModel.EmployeeRepository)DataModel.DataBase.GetRepository<DataModel.EmployeeRepository, DataModel.EmployeeEntity>();
            DataModel.ConnectionRepository conRep = (DataModel.ConnectionRepository)DataModel.DataBase.GetRepository<DataModel.ConnectionRepository, DataModel.ConnectionEntity>();
            foreach (int id in conRep.GetAllConnectionsWithEmployee((int)parameter).Select(x => x.Id))
            {
                conRep.Delete(id);
            }

            empRep.Delete((int)parameter);
        }
    }
}
